from time import sleep
import re

env_heap = {}
env_heap_point = 0
env_stack_analyse = []
analyse_this_queue_len = 0

def env_2heap(env_2heap_item,env_heap_point):
  global env_heap
  env_heap.update({hex(env_heap_point):env_2heap_item})

def env_2stack(this_stack,item,this_stack_point=None):
  if this_stack_point == None:
    this_stack_point = len(this_stack)
  global env_heap_point
  env_2heap(item, env_heap_point)
  return this_stack.insert(this_stack_point,hex(env_heap_point))

def get_bigBracket(this_stack,this_stack_point=-1):
  global env_heap,env_heap_point,analyse_this_queue_len
  string_1 = env_heap[this_stack[this_stack_point]]
  while True:
    try:
      posi = re.search(r"\{[^\{\}]+\}",string_1).span()
      string_2 = string_1[posi[0]:posi[1]].strip(r'\{\}')
      string_1 = "%s %s"%(string_1[:posi[0]],string_1[posi[1]:])
      #print(string_2)
      #print(string_1)
      env_heap_point+=1
      env_2stack(this_stack,string_2)
      analyse_this_queue_len += 1
    except:
      env_heap_point+=1
      env_2stack(this_stack,string_1)
      analyse_this_queue_len += 1
      break
  return this_stack[1:]

def get_blank(this_stack):
  global env_heap,env_heap_point,analyse_this_queue_len
  this_stack_temp = this_stack[:analyse_this_queue_len]
  #print(this_stack_temp)
  for i_item in range(len(this_stack_temp)):
    string_1 = env_heap[this_stack_temp[i_item]]
      
    while re.search(r"[^\s]+",string_1):
      try:
        posi = re.search(r"[^\s]+",string_1).span()
        string_2 = string_1[posi[0]:posi[1]].strip(r' ')
        string_1 = "%s%s"%(string_1[:posi[0]],string_1[posi[1]:])
        env_heap_point+=1
        env_2stack(this_stack,string_2,this_stack_point=-len(this_stack_temp)+i_item)
        analyse_this_queue_len += 1
      except:
        env_heap_point+=1
        env_2stack(this_stack,string_1)
        analyse_this_queue_len += 1
  return this_stack


def get_input():
  global env_heap,env_heap_point,analyse_this_queue_len
  analyse_this_queue_len = 0
  env_input = input()
  env_heap_point+=1
  env_2heap(env_input,env_heap_point)
  return env_input

def get_input_default():
  global env_heap,env_heap_point,analyse_this_queue_len
  analyse_this_queue_len = 0
  env_input = r"g{a{b}c}d{e}f"
  env_heap_point+=1
  env_2heap(env_input,env_heap_point)
  return env_input

env_2stack(env_stack_analyse,get_input_default())
env_stack_analyse = get_bigBracket(env_stack_analyse,-1)
env_stack_analyse = get_blank(env_stack_analyse)
print(env_heap)
print(env_stack_analyse)
